package ymbky.firstcodesunnyweather.planbook

import android.app.Activity
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.dailyplan_item.view.*

class DailyplanAdapter(val context: Activity, private var recordList: List<Record>):
    RecyclerView.Adapter<DailyplanAdapter.ViewHolder>() {
    inner class ViewHolder(view: View):RecyclerView.ViewHolder(view){
        val titleTv: TextView =view.tv_title
        val affairTv: TextView =view.tv_affair
        val timeTV:TextView=view.tv_time
        val rlContainer:ViewGroup=view.rl_item_container
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view= LayoutInflater.from(parent.context).inflate(R.layout.dailyplan_item,parent,false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val dailyplan = recordList.get(position)

        holder.titleTv.text= dailyplan.title
        holder.affairTv.text=dailyplan.affair
        holder.timeTV.text=dailyplan.createTime
        holder.rlContainer.setOnClickListener{
            val intent= Intent(context,DailyplanActivity::class.java)
            intent.putExtra("record",dailyplan)
            context.startActivity(intent)

        }
//        holder.rlContainer.setOnLongClickListener {
//    //设置长按弹出对话框
//        }
    }

    override fun getItemCount()=recordList.size

//    fun refreshData(records: MutableList<Record>){
//
//        recordList = records
//
//        notifyDataSetChanged()
//    }

}